﻿// Study1012.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第十章 STL和泛型设计 关联容器 多重映射

#include <iostream>
#include <map>
#include <utility>
#include <string>
using namespace std;

int main()
{
	multimap<string, string>courses;
	courses.insert(make_pair("C++", "2-6"));
	courses.insert(make_pair("COMPILER", "3-1"));
	courses.insert(make_pair("COMPILER", "5-2"));
	courses.insert(make_pair("OS", "1-2"));
	courses.insert(make_pair("OS", "4-1"));
	courses.insert(make_pair("OS", "5-5"));

	string name;
	int count;
	do
	{
		cin >> name;
		count = courses.count(name);
		if (count == 0)
		{
			cout << "cannot find this course!" << endl;
		}
	}     while (count == 0);
	cout << count << " lessons per week:";
	typedef multimap<string, string>::iterator CourseIter;
	auto range = courses.equal_range(name);
	for ( auto iter=range.first;iter!=range.second;++iter)
	{
		cout << iter->second << " ";
	}
	cout << endl;

	return 0;

}

